#include "hud.h"

#include "pipeline.h"
#include "timer.h"

Hud::Hud(Game* game) : GameObject(game) {
    this->frame = 0;
    this->lblAsteroids = new Label(this->GetGame());
    this->lblAsteroids->SetPosition(Point(-300, 210));
    this->lblCameraPosition = new Label(this->GetGame());
    this->lblCameraPosition->SetPosition(Point(-300, -240));
    this->lblFps = new Label(this->GetGame());
    this->lblFps->SetPosition(Point(200, -240));
    this->lblFps->SetTextAlignment(TEXTALIGNMENT_CENTER);
    this->numberOfAsteroidsDrawn = 0;
}

Hud::~Hud(void) {
    delete this->lblAsteroids;
    delete this->lblCameraPosition;
    delete this->lblFps;
}

void Hud::SetNumberOfAsteroidsDrawn(int val) {
    this->numberOfAsteroidsDrawn = val;
}

void Hud::Draw(float timeDelta) {
    this->lblAsteroids->Draw(timeDelta);
    this->lblCameraPosition->Draw(timeDelta);
    this->lblFps->Draw(timeDelta);
}

void Hud::Initialize() {
    this->lblAsteroids->Initialize();
    this->lblCameraPosition->Initialize();
    this->lblFps->Initialize();
}

void Hud::LoadContent() {
    this->lblAsteroids->LoadContent();
    this->lblCameraPosition->LoadContent();
    this->lblFps->LoadContent();
}

void Hud::Update(float timeDelta) {
    char buffer[100];
    sprintf(buffer, "Number of asteroids: %d", this->numberOfAsteroidsDrawn);
    this->lblAsteroids->SetText(string(buffer));
    sprintf(buffer,
            "Camera Position (x, y, z) = (%3.1f, %3.1f, %3.1f)",
            Pipeline.GetCameraX(), Pipeline.GetCameraY(), Pipeline.GetCameraZ());
    this->lblCameraPosition->SetText(string(buffer));
    sprintf(buffer, "Frame: %d\nFPS: %.1f" , this->frame++, this->GetGame()->GetFPS());
    this->lblFps->SetText(string(buffer));
}